package com.v2future.sjt.collegecheckingattendance.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;

import com.v2future.sjt.collegecheckingattendance.R;
import com.v2future.sjt.collegecheckingattendance.personal.bean.OnePolicitsBean;

import java.util.List;

/**
 * 填写订单页，场次选择dialog
 * @author shijianting
 * @time 2016/3/22 13:41
 */
public class PopupWindowSelectDialog extends Dialog {

    private Context mContext;

    private List<String> dataList;

    private ListViewInScroll sessionLv;

    private PopupWindowSelectAdapter adapter;

    private ClickListener mListener;

    public interface ClickListener{
        public void selecData(String date, int position);
    }

    public PopupWindowSelectDialog(Context context, List<String> dataList, ClickListener listener) {
        super(context);
        init(context, dataList, listener);
    }

    public PopupWindowSelectDialog(Context context, int theme, List<String> dataList, ClickListener listener) {
        super(context, theme);
        init(context, dataList, listener);
    }

    public void init(Context context, List<String> dataList, ClickListener listener){
        this.mContext = context;
        this.dataList = dataList;
        this.mListener = listener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LayoutInflater inflater = LayoutInflater.from(mContext);
        View view = inflater.inflate(R.layout.dialog_session_select, null);
        sessionLv = (ListViewInScroll) view.findViewById(R.id.lv_sessions);
        adapter = new PopupWindowSelectAdapter(dataList, mContext);
        sessionLv.setAdapter(adapter);
        sessionLv.setOnItemClickListener(itemClickListener);
        setContentView(view);
    }

    AdapterView.OnItemClickListener itemClickListener = new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (null != mListener) {
                String date = dataList.get(position);
                mListener.selecData(date, position);
                PopupWindowSelectDialog.this.dismiss();
            }
        }
    };
}
